﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Data.Abstract;
using System.Data.SQLite;
using System.Data;

namespace Data
{
    public class Persona : BaseObject<SimplePersona>
    {
        #region Propiedades
      
        new public DalPersona Dal
        {
            get
            {
                if (_Dal == null) _Dal = new DalPersona();
                return (DalPersona)_Dal;
            }
        }
        CollectionVisita _Visitas;
        public CollectionVisita Visitas
        {
            get { return _Visitas; }
        }
        CollectionPosicion _Posiciones;
        public CollectionPosicion Posiciones
        {
            get { return _Posiciones; }
        }

     
        #endregion
        #region Procedimientos
         public Persona(): base()
        {
            _Dal = new DalPersona();
        }
         public Persona(SimplePersona Simple): base()
        {
            this._Simple = Simple;
            _Dal = new DalPersona(getConn());

        }
         public Persona(SimplePersona Simple, SQLiteConnection conn )
             : base()
         {
             _Dal = new DalPersona(conn);
             _Simple = Simple;
         }
  
         
        #endregion
        #region Metodos
         public CollectionVisita LoadVisitas()
         {
             CollectionVisita cv = new CollectionVisita();
             cv.LoadByPersona(this.Simple.Id);
             this._Visitas = cv;
             return cv;
         }
         public CollectionPosicion LoadPosiciones()
         {
             CollectionPosicion cp = new CollectionPosicion();
             cp.LoadByPersona(this.Simple.Id);
             this._Posiciones = cp;
             return cp;
         }
        
        public override void Insert()
        {
            this.Dal.Insert(this._Simple);
        }
        public override void Update()
        {
            this.Dal.Update(this._Simple);
        }
        public override void Delete()
        {
            throw new NotImplementedException();
        }

        #endregion
        SQLiteConnection getConn()
        {
            if (this._Simple != null)
            {
                //News n = new News();
                //n.Load(this._Simple.NewsId);
                //string tempDir =  Data.Configuration.Context.CurrentContext.GetTempPath(n.Simple.RespRandom, Data.Configuration.TipoBaseEnum.System).FullName;
                //System.IO.FileInfo fi = new System.IO.FileInfo(System.IO.Path.Combine(tempDir, "ClientInfo.db"));
                return new SQLiteConnection("data source=" );//+ fi.FullName);
            }
            return new SQLiteConnection();
        }

       
    }
}
